<template>
  <div class="app-container home" >
    <el-row :gutter="20">
      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>采矿对标分析系统</h2>
        <p>
          欢迎来到采矿对标分析系统
        </p>
        <p>
          <b>当前版本:</b> <span>v{{ version }}</span>
        </p>
      </el-col>

      <el-col :sm="24" :lg="12" style="padding-left: 20px">
        <h2>通知看板
          <el-tooltip class="item" content="查看历史通知" placement="right-start">
            <el-button icon="el-icon-search" circle @click="table = true"></el-button>
          </el-tooltip>
        </h2>
        <el-timeline>
          <el-timeline-item
            v-for="(notice, index) in this.latestNoticeList"
            :key="index"
            :timestamp="notice.createTime"
            placement="top"
          >
            <el-card>
            <h4>标题：{{ notice.noticeTitle }}</h4>
            <p>正文：{{ notice.noticeText }}</p>
            <span>来自：{{ notice.createBy }}</span>
            </el-card>
          </el-timeline-item>
        </el-timeline>
      </el-col>
      <el-drawer
        title="历史通知面板"
        :visible.sync="table"
        direction="rtl"
        size="50%">
        <el-table v-loading="loading" :data="this.noticeList" :default-sort = "{prop: 'createTime', order: 'descending'}">
          <el-table-column label="创建时间" align="center" prop="createTime"  sortable/>
          <el-table-column label="创建者" align="center" prop="createBy" />
          <el-table-column
            label="公告标题"
            align="center"
            prop="noticeTitle"
          />
          <el-table-column
            label="公告正文"
            align="center"
            prop="noticeText"
            >
          </el-table-column>
        </el-table>
      </el-drawer>

    </el-row>

  </div>
</template>


<script>
import {listNotice} from "@/api/system/notice";
export default {
  name: "Index",
  data() {
    return {
      // 遮罩层
      loading: true,
      table: false,
      //消息列表
      noticeList:[],
      noticeListLength:null,
      // 查询参数
      queryParams: {

        noticeTitle: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      //时间
      value: new Date(),
      // 版本号
      version: "1.0.1",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告列表 */
    async getList() {
      this.loading = true;
      await listNotice(this.queryParams).then(response => {
        for (let i = response.rows.length-1; i >= 0; i--){
          this.noticeList.push(response.rows[i]);
        }
        this.noticeListLength = this.noticeList.length
        // console.log("this.noticeList",this.noticeList)
        // console.log("this.noticeListLength",this.noticeList.length)
        this.loading = false;
      });
    },
  },
  computed: {
    latestNoticeList() {
      return this.noticeList.slice(0, 3); // 只返回最新的三条数据
    }
  },

};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

